package com.bolong.gmgc.redis;

import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

@Component
public class Subscriber implements Runnable {

	@Autowired
	private KeyExpiredListener keyExpiredListener;

	// private static JedisPool jedisPool;


	@Autowired
	private JedisPool jedisPool;

	private Thread tokenExpireListener;

	@Override
	public void run() {
		Jedis jedis = jedisPool.getResource();
		jedis.psubscribe(keyExpiredListener, "__keyevent@0__:expired");
	}

	@PostConstruct
	public void start() {
		if (tokenExpireListener == null) {
			tokenExpireListener = new Thread(this);
			tokenExpireListener.start();
		}
	}

}
